package com.baitiaojun.video.config;

import com.baitiaojun.video.config.properties.CommentsMQProperties;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfig {

    @Autowired
    private CommentsMQProperties properties;

    @Bean
    public Exchange exchange() {
        return ExchangeBuilder.topicExchange(properties.getExchange()).durable(true).build();
    }

    @Bean
    public Queue queue() {
        return QueueBuilder.durable(properties.getQueue()).build();
    }

    @Bean
    public Binding queueBindingExchange(Queue queue, Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(properties.getRoutingKey()).noargs();
    }
}